﻿<Window x:Class="AppControl.ContactsWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Address Book" MinHeight="610" MaxHeight="610" MinWidth="620" MaxWidth="620" 
        Closed="OnContactsWindowClosed" Name="AddressBook" WindowStartupLocation="CenterOwner">

    <!--<Window.Resources>
        <LinearGradientBrush x:Key="BlueRedGradientBrush"
            StartPoint="0,0" EndPoint="1,1">
            <GradientStop Color="LightGray" Offset="0" />
            <GradientStop Color="Beige" Offset="0.5" />
            <GradientStop Color="LightGray" Offset="1" />
        </LinearGradientBrush>

        <Style TargetType="{x:Type Button}">
            <Setter Property="Background" Value="{StaticResource BlueRedGradientBrush}"/>
        </Style>
    </Window.Resources>-->

    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    </Window.Resources>

    <Grid Background="{StaticResource GridBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="102"/>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <Canvas Grid.Row="0" Background="{DynamicResource BrushContacts}">
            <Canvas.Resources>

                <LinearGradientBrush x:Key="BrushContacts" EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="White" Offset="1"/>
                    <GradientStop Color="#FFC7C7C7" Offset="0.982"/>
                    <GradientStop Color="#FF858585" Offset="0.661"/>
                    <GradientStop Color="#FF858585" Offset="0.989"/>
                    <GradientStop Color="#FF727272" Offset="0.979"/>
                </LinearGradientBrush>

            </Canvas.Resources>
            <Label Content="Name*" Height="24" Canvas.Left="15" Canvas.Top="10" Foreground="#FF11A68B" FontSize="13" FontWeight="Bold">
                <Label.Effect>
                    <DropShadowEffect/>
                </Label.Effect>
            </Label>
            <TextBox Name="PersonName" MaxLength="30" Width="150" Height="24"
                     Canvas.Left="70" Canvas.Top="10" FontSize="12" VerticalContentAlignment="Center"/>
            <Label Content="Mobile*" Height="24" Canvas.Left="10" Canvas.Top="39" Foreground="#FF11A68B" FontWeight="Bold" FontSize="13">
                <Label.Effect>
                    <DropShadowEffect/>
                </Label.Effect>
            </Label>
            <TextBox Name="Mobile" MaxLength="15" Width="150" Height="24"
                     Canvas.Left="70" Canvas.Top="39" FontSize="12" VerticalContentAlignment="Center"/>
            <Label Content="E-mail" Height="29" Canvas.Left="10" Canvas.Top="63" Foreground="#FF11A68B" FontWeight="Bold" FontSize="14" RenderTransformOrigin="0.404,-0.25">
                <Label.Effect>
                    <DropShadowEffect RenderingBias="Quality"/>
                </Label.Effect>
            </Label>
            <TextBox Name="PersonEmail" MaxLength="30" Width="150" Height="24"
                     Canvas.Left="70" Canvas.Top="68" FontSize="12" VerticalContentAlignment="Center"/>

            <Label Content="Date of birth" Height="24" Canvas.Left="225" Canvas.Top="24" Foreground="#FF11A68B" FontWeight="Bold" FontSize="13">
                <Label.Effect>
                    <DropShadowEffect/>
                </Label.Effect>
            </Label>
            <TextBox Name="PersonBirthday" MaxLength="10" Width="100" Height="24"
                     Canvas.Left="315" Canvas.Top="24.5" FontSize="12" VerticalContentAlignment="Center"/>
            <Label Content="Group" Height="25" Canvas.Left="260" Canvas.Top="54"
                   Foreground="#FF11A68B" FontWeight="Bold" FontSize="13">
                <Label.Effect>
                    <DropShadowEffect RenderingBias="Quality"/>
                </Label.Effect>
            </Label>

            <ComboBox Name="GroupType" FontSize="12" Width="100" SelectedIndex="3"
                      Height="22" Canvas.Left="315" Canvas.Top="58">
                <ComboBoxItem Content="Family"/>
                <ComboBoxItem Content="Friends"/>
                <ComboBoxItem Content="Business"/>
                <ComboBoxItem Content="Other"/>
            </ComboBox>

            <Button Content="Add" Width="60" Height="30" FontSize="14"
                    Background="{StaticResource ButtonBrush}"
                    Style="{DynamicResource RoundedButton}" Click="OnAddBtnClick"
                    Canvas.Left="472" Canvas.Top="36">
                <Button.Effect>
                    <DropShadowEffect/>
                </Button.Effect>
            </Button>
        </Canvas>


        <DataGrid Name="preview" Grid.Row="1" RowHeight="30" FontSize="13" GridLinesVisibility="Horizontal"
                  CanUserDeleteRows="False" CanUserAddRows="False" PreviewKeyDown="OnDelKeyboardKey"
                  ItemsSource="{Binding}" AutoGenerateColumns="False" SelectionUnit="FullRow" VerticalScrollBarVisibility="Visible"
                  Background="#FFC9DCD9" BorderBrush="#FF7E8E9E" Foreground="#FF030708" RowDetailsVisibilityMode="Collapsed"
                  SelectionChanged="preview_SelectionChanged"  ColumnHeaderHeight="0" RowHeaderWidth="0">

            <!--On selection colour the whole row-->
            <DataGrid.CellStyle>
                <Style TargetType="DataGridCell">
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter Property="Background" Value="#FF11A68B"/>
                            <Setter Property="BorderThickness" Value="0"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.CellStyle>

            <!--Show details when mouse double-clicked-->
            <DataGrid.RowStyle>
                <Style TargetType="{x:Type DataGridRow}">
                    <EventSetter Event="MouseDoubleClick" Handler="RowDoubleClick"/>
                </Style>
            </DataGrid.RowStyle>

            <DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <Canvas Height="140" Background="DarkGray">
                        <Image Source="{Binding Path=Picture,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                               Canvas.Left="37" Canvas.Top="0" Height="110" Width="110"/>

                        <Button Canvas.Left="490" Canvas.Top="8" FontSize="14" Width="80"
                                Content="Add picture" Click="OnAddPictureClick" Height="25"
                                Style="{DynamicResource RoundedButton}"
                                Background="{StaticResource ButtonBrush}">
                            <Button.Effect>
                                <DropShadowEffect/>
                            </Button.Effect>
                        </Button>

                        <Button Canvas.Left="490" Canvas.Top="41" FontSize="14" Width="80"
                                Content="Send mail" Click="OnSendMailClick" Height="25"
                                Style="{DynamicResource RoundedButton}" 
                                Background="{StaticResource ButtonBrush}">
                            <Button.Effect>
                                <DropShadowEffect/>
                            </Button.Effect>
                        </Button>

                        <Button Canvas.Left="490" Canvas.Top="74" FontSize="14" Width="80"
                                Content="Edit" Click="OnContactEditClick" Height="25"
                                Style="{DynamicResource RoundedButton}" Name="EditBtn"
                                Background="{StaticResource ButtonBrush}">
                            <Button.Effect>
                                <DropShadowEffect/>
                            </Button.Effect>
                        </Button>

                        <Button Canvas.Left="490" Canvas.Top="107" FontSize="14" Width="80"
                                Content="Delete" Click="OnContactDeleteClick" Height="25"
                                Style="{DynamicResource RoundedButton}" 
                                Background="{StaticResource ButtonBrush}">
                            <Button.Effect>
                                <DropShadowEffect/>
                            </Button.Effect>
                        </Button>

                        <TextBox Canvas.Left="0" Canvas.Top="115" FontWeight="Bold" Height="20" Background="Transparent"
                                 Text="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                 Width="180" TextAlignment="Center" FontSize="15" FontStyle="Italic" BorderThickness="0"
                                 IsReadOnly="True"/>

                        <TextBlock Canvas.Left="190" Canvas.Top="28" Text="Mobile:" Height="18" FontWeight="Bold"
                                   Width="95" TextAlignment="Right" FontSize="14" FontStyle="Italic" VerticalAlignment="Center"/>
                        <TextBox Canvas.Left="290" Canvas.Top="26" Height="20" IsReadOnly="True"
                                 Text="{Binding Path=PhoneNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                 Width="200" TextAlignment="Left" FontSize="16" Background="Transparent"
                                 BorderThickness="0" VerticalContentAlignment="Center"/>

                        <TextBlock Canvas.Left="190" Canvas.Top="63" Text="e-mail:" Height="18" FontWeight="Bold"
                                   Width="95" TextAlignment="Right" FontSize="14" FontStyle="Italic" VerticalAlignment="Center"/>
                        <TextBox Canvas.Left="290" Canvas.Top="62" Height="20" IsReadOnly="True"
                                 Text="{Binding Path=Email, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                 Width="200" TextAlignment="Left" FontSize="14" Background="Transparent" 
                                 BorderThickness="0" VerticalContentAlignment="Center"/>

                        <TextBlock Canvas.Left="190" Canvas.Top="96" Text="Date of birth:" Height="18" FontWeight="Bold"
                                   Width="95" TextAlignment="Right" FontSize="14" FontStyle="Italic" VerticalAlignment="Center"/>
                        <TextBox Canvas.Left="290" Canvas.Top="94" Height="22" IsReadOnly="True"
                                 Text="{Binding Path=Birthday, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, 
                                 ConverterCulture='bg-BG', StringFormat=d}" VerticalContentAlignment="Center"
                                 Width="200" TextAlignment="Left" FontSize="14" Background="Transparent"
                                 BorderThickness="0"/>
                    </Canvas>
                </DataTemplate>
            </DataGrid.RowDetailsTemplate>

            <DataGrid.Columns>
                <DataGridTemplateColumn Width="30" IsReadOnly="True"
                                        CanUserReorder="False" CanUserResize="False">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Height="25" Width="25" Source="{Binding Path=Icon}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTextColumn Header="Name" Binding="{Binding Path=Name}"
                                    CanUserReorder="False" Width="525" IsReadOnly="True">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="VerticalAlignment" Value="Center"/>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>

                <DataGridTemplateColumn Width="35" IsReadOnly="True" 
                                        CanUserReorder="False" CanUserResize="False">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                                <Image.Style>
                                    <Style TargetType="{x:Type Image}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding UpcomingBirthday}" Value="True">
                                                <Setter Property="Source" Value="Resources/Birthday.png"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>

            <DataGrid.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander>
                                            <Expander.Header>
                                                <StackPanel Orientation="Horizontal" Margin="200,15">
                                                    <TextBlock Text="{Binding Name}" Margin="2"/>
                                                    <TextBlock Text="contacts" Margin="2"/>
                                                    <TextBlock Text="(" Margin="2"/>
                                                    <TextBlock Text="{Binding Path=ItemCount}" Margin="2"/>
                                                    <TextBlock Text=")" Margin="2"/>
                                                </StackPanel>
                                            </Expander.Header>
                                            <ItemsPresenter />
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </DataGrid.GroupStyle>
        </DataGrid>
    </Grid>
</Window>
